# 使用 Ubuntu 20.04 作为基础镜像
FROM ubuntu:20.04

# 设置 docker name 和 docker version
LABEL name="czy" version="1.0"

# 在dockerfile中添加
RUN /bin/bash -c "source /root/.bashrc"
# 修改sh为bash
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# 设置 apt-get 镜像源
RUN sed -i 's/archive.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
RUN sed -i 's/security.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list

# 设置时区
ENV TIME_ZONE Asia/Shanghai
RUN apt-get update && \
    apt-get install -y tzdata && \
    rm -rf /var/lib/apt/lists/*
RUN ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && \
    echo $TIME_ZONE > /etc/timezone
RUN dpkg-reconfigure -f noninteractive tzdata
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/cache/* /var/log/* /usr/share/doc/* ~/.cache/*

# 安装基本工具
RUN apt-get update && \
    apt-get install -y \
    sudo \
    git \
    zsh \
    curl \
    wget \
    vim \
    python3-pip \
    build-essential \
    iproute2 \
    net-tools \
    python3-yaml

# 创建用户 czy
RUN addgroup --gid 1001 czy && \
    useradd -m -u 1001 -g 1001 -s /bin/zsh czy && \
    echo "czy ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# 切换到 czy 用户
USER czy

ENV GO_VERSION="go1.21.3"
ENV GO_PATH="/home/czy/go"

# change command line to highlight
RUN sed -i 's/#force_color_prompt=yes/force_color_prompt=yes/g' ~/.bashrc

# 在用户主目录下安装 Oh My Zsh
RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# change zs theme to ys
RUN sed -i 's/ZSH_THEME="robbyrussell"/ZSH_THEME="ys"/g' ~/.zshrc

# 设置 PYTHONPATH，防止安装 ceph 后找不到 ceph_argparse.py 等文件
RUN echo "export PYTHONPATH=/usr/local/lib/python3/dist-packages/:\$PYTHONPATH" >> ~/.zshrc
RUN echo "export PYTHONPATH=/usr/local/lib/python3.8/dist-packages/:\$PYTHONPATH" >> ~/.zshrc
RUN echo "export PYTHONPATH=/usr/local/lib/python3/dist-packages/:\$PYTHONPATH" >> ~/.bashrc
RUN echo "export PYTHONPATH=/usr/local/lib/python3.8/dist-packages/:\$PYTHONPATH" >> ~/.bashrc

# 修改pip源
RUN pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
RUN pip config set global.trusted-host https://mirrors.ustc.edu.cn

# 安装 golang
RUN cd ~ && wget https://mirrors.ustc.edu.cn/golang/${GO_VERSION}.linux-amd64.tar.gz && \
    sudo tar -xzf ${GO_VERSION}.linux-amd64.tar.gz -C /usr/local/ && \
	rm ${GO_VERSION}.linux-amd64.tar.gz

# add env PATH
RUN echo "export GOROOT=/usr/local/go" | sudo tee -a /etc/profile
RUN	echo "export GOPATH=$GO_PATH" | sudo tee -a /etc/profile
RUN	echo 'export PATH=/usr/local/go/bin:$PATH' | sudo tee -a /etc/profile
RUN echo "export GOROOT=/usr/local/go" >> ~/.zshrc
RUN	echo "export GOPATH=$GO_PATH" >> ~/.zshrc
RUN	echo 'export PATH=/usr/local/go/bin:$PATH' >> ~/.zshrc

RUN source /etc/profile && go env -w GOPROXY=https://goproxy.io,direct
RUN source /etc/profile && go env -w GO111MODULE=on
RUN mkdir -p $GO_PATH/src

# 设置 zsh 为默认 shell
SHELL ["/bin/zsh", "-l"]